﻿#nullable enable

using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace PHMEE.EnergyEfficiency;

public interface ILogAbstractRepository
{
    /// <summary>
    /// 根据 ts 查询 LogAbstract 数据
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="ts"></param>
    /// <returns></returns>
    Task<LogAbstract?> GetOrDefaultAsync(Guid vesselId, DateTime ts);

    /// <summary>
    /// 计数，时间前闭后开区间
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="startDateTimeUtc"></param>
    /// <param name="endDateTimeUtc"></param>
    /// <returns></returns>
    Task<int> CountAsync(Guid vesselId, DateTime startDateTimeUtc, DateTime endDateTimeUtc);

    /// <summary>
    /// 时间前闭后开区间查询，按 Ts DESC 排序
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="startDateTimeUtc"></param>
    /// <param name="endDateTimeUtc"></param>
    /// <param name="skipCount"></param>
    /// <param name="maxResultCount"></param>
    /// <returns></returns>
    Task<List<LogAbstract>> GetListDescAsync(Guid vesselId, DateTime startDateTimeUtc,
        DateTime endDateTimeUtc,
        int skipCount, int maxResultCount);

    /// <summary>
    /// 时间前闭后开区间查询
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="startDateTimeUtc"></param>
    /// <param name="endDateTimeUtc"></param>
    /// <returns></returns>
    Task<List<LogAbstract>> GetListClosedOpenAsync(Guid vesselId, DateTime startDateTimeUtc,
        DateTime endDateTimeUtc);

    /// <summary>
    /// 时间前开后闭区间查询
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="startDateTimeUtc"></param>
    /// <param name="endDateTimeUtc"></param>
    /// <returns></returns>
    Task<List<LogAbstract>> GetListOpenClosedAsync(Guid vesselId, DateTime startDateTimeUtc,
        DateTime endDateTimeUtc);

    /// <summary>
    /// 获取 time 前（包含 time）最新的一条 “离港” 类型的 Log abstract
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="dateTimeUtc"></param>
    /// <returns></returns>
    Task<LogAbstract?> GetLatestDepartureTypeLogAbstractOrDefaultBeforeOrEqualTimeAsync(Guid vesselId,
        DateTime dateTimeUtc);

    /// <summary>
    /// 获取距 DateTime time （包含 time）最近的一条 log abstract
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="dateTimeUtc"></param>
    /// <returns></returns>
    Task<LogAbstract?> GetLatestLogAbstractOrDefaultAsync(Guid vesselId, DateTime dateTimeUtc);

    /// <summary>
    /// 获取距 time （包含 time）最近的一条 Adjustment（调整） log abstract
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="dateTimeUtc"></param>
    /// <returns></returns>
    Task<LogAbstract?> GetLatestAdjustLogAbstractOrDefaultBeforeOrEqualTimeAsync(Guid vesselId,
        DateTime dateTimeUtc);

    /// <summary>
    /// 获取距 time （不包含 time）最早的一条 Adjustment（调整） log abstract
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="dateTimeUtc"></param>
    /// <returns></returns>
    Task<LogAbstract?> GetEarliestAdjustLogAbstractOrDefaultAfterTimeAsync(Guid vesselId,
        DateTime dateTimeUtc);

    /// <summary>
    /// 获取最后一条 LogAbstract
    /// </summary>
    /// <param name="vesselId"></param>
    /// <returns></returns>
    Task<LogAbstract?> GetLastLogAbstractOrDefaultAsync(Guid vesselId);

    /// <summary>
    /// 插入
    /// </summary>
    /// <param name="logAbstract"></param>
    /// <param name="vesselId"></param>
    Task InsertAsync(LogAbstract logAbstract, Guid vesselId);

    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="vesselId"></param>
    /// <param name="ts"></param>
    Task DeleteAsync(Guid vesselId, DateTime ts);
}